package com.yitiao.data_algorithms.leetcode.editor.cn;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class LianBiaoZhongDaoShuDiKgeJieDianLcof{
    //leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode first = head;
        ListNode tail = head;
        for (int i = 0; i < k; i++) {
            first = first.next;
        }
        while (first!=null){
            first = first.next;
            tail = tail.next;
        }
        return tail;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}